<!DOCTYPE html>
<html>
<head>
    <title>支付 | 在线消费</title>
<include file="Public/head"/>

</head>
<body>
    <div id="wrapper">
<include file="Public/leftmenu"/>
        <div id="page-wrapper" class="gray-bg">
     <include file="Public/top"/>
            <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>线上消费</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a>Member</a>
                        </li>
                
                        <li class="active">
                            <strong>消费</strong>
                        </li>
                    </ol>
                </div>
                <div class="col-lg-2">

                </div>
            </div>
            <div class="wrapper wrapper-content animated fadeIn">
                <div class="row">
                    <div class="col-lg-6">
                        <div class="tabs-container weixin">
                        <!-- <ul class="nav nav-tabs">
                                <li class="active"><a data-toggle="tab" href="#tab-1">充值</a></li>
                                <li class=""><a data-toggle="tab" href="#tab-2">消费</a></li>
                            </ul> -->
                            <div class="tab-content">
                                <div id="tab-1" class="tab-pane active">
                                    <div class="panel-body">
                                        <div class="row">
                                            <div class="col-sm-12 micropay">
                                                <h3 class="m-t-none m-b">消费</h3>
                                                <p>要确认好消费信息哦(⊙o⊙)</p>

                                            <form role="form" action="?s=Member/recharge" id="form1">
                                                <input type="hidden" name="cid" value="{$id}" />
                                                <input type="hidden" name="e_type" value="1" />
                                                <input type="hidden" name="giving" value="0" />
                                                <input type="hidden" name="e_point" value="0" />
                                                <input type="hidden" name="money" value="0" />
                                                <div class="form-group" >
                                                    <label>持卡人</label>
                                                    <input  type="text" placeholder="持卡人" value="{$name}"  disabled class="form-control">
                                                </div>
                                                <div class="form-group" >
                                                    <label>会员手机号</label>
                                                    <input  type="text" placeholder="手机号" value="{$mobile}"  disabled class="form-control">
                                                </div>
                                                <div class="form-group">
                                                    <label>消费金额</label>
                                                    <input onkeyup="this.value=this.value.replace(/\D/g,'')" type="text" placeholder="支付金额" name="total" class="form-control">
                                                </div>
                                                <notempty name="coupons">
                                                    <div class="form-group">
                                                        <label>可用卡券</label>
                                                        <ul style="list-style-type:none">
                                                        <volist name='coupons' id="vo">
                                                            <li><input type="radio" name='coupon' value="{$vo.pid}" ctype="{$vo.type}" dataa="{$vo.jianmian}" datab="{$vo.dikou}">卡券名称:{$vo.title} &nbsp; 卡券类型:<eq name="vo['type']" value='1'>体验券 &nbsp; 剩余次数 {$vo.surplus}<else />代金券  &nbsp; 满 {$vo.jianmian} 元减 {$vo.dikou} 元</eq></li>
                                                        </volist>
                                                            <li><input type="radio" name='coupon' value="0">不使用优惠券</li>
                                                        </ul>
                                                    </div>
<!--                                                     <div class="form-group">
                                                        <label>使用卡券</label>
                                                        <input  onkeyup="this.value=this.value.replace(/\D/g,'')"  type="text" placeholder="填写要使用的卡券id" name="coupon" class="form-control">
                                                    </div> -->
                                                </notempty>

                                                <div class="form-group">
                                                    <label>消费备注</label>
                                                    <input type="text" placeholder="消费备注(选填)" name="note" class="form-control">
                                                </div>
                                                <div>
                                                    <input type='radio' name="paytype" value='0' checked="true">余额支付<input type='radio' name='paytype' value='1'>现金支付

                                                    <br /><div class="error pull-right">支付金额：<span id="realmoney">0</span> 元</div><br /><br />
                                                    <button  onclick="return checkc('form1');" class="btn btn-sm btn-primary pull-right m-t-n-xs" type="button" >
                                                        <strong>在线消费</strong>
                                                    </button>
                                                </div>
                                            </form>
                                        </div>
                                        </div>
                                    </div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
    <include file="Public/footer"/>
        </div>
    </div>
    
    <script>
        function cphone(d,id){
            var pattern = /^1[34578]\d{9}$/;
        
            if (pattern.test(d.value)) {
            
                    $.post('?s=Member/getCard',{mobile:d.value}, function(data){
                        $("#"+id).html('');
                      $("#"+id).html(data);
                     
                    });
        
                return true;
            }else{
                
                            swal("错误", "手机号没输入对哦 :)", "error");return false;
            }
        }
        function checkc(d){
           var c = $("#"+d);
                swal({
                title: "提示 :)",
                    text: "确认此操作？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    closeOnConfirm: false
                }, function () {
                  
                    var e = c.serialize();  
                    $.post(c.attr('action'),e, function(data){
                        console.log(data);
                        if(data.error == 0){
                            
                            swal("成功!", data.msg, "success");
                            window.location.href = "{:U('Member/lists')}";
                        }else{
                            swal("失败!", data.msg, "error");
                            //window.history.back(-1)
                            // $("#"+d).reset(); 
                        }
                    },'JSON');
                });
            }
        function moneyrefresh(money,giving){
            $("input[name='money']").attr("value", money);
            $("#realmoney").html(money);
            $("input[name='giving']").attr("value", giving);
        }

        $(document).ready(function(){
            $("input[name='total']").change(function(){
                var coupon = $("input[name='coupon']").val();
                var total  = $(this).val();
                if(coupon == 0 || coupon == null){
                    moneyrefresh(total,0);
                }else{
                    var type = $("input[name='coupon']:checked").attr("ctype");
                    if(type == 1){
                        //体验券
                        moneyrefresh(0,total);
                    }else{
                        var jianmian = $("input[name='coupon']:checked").attr("dataa");
                        var dikou    = $("input[name='coupon']:checked").attr("datab");
                        if(parseInt(total) >= parseInt(jianmian)){
                            moneyrefresh(total-dikou,dikou);
                        }else{
                            moneyrefresh(total,0);
                        }
                    }
                }
            })

            $("input[name='coupon']").change(function(){
                var ctype = $(this).attr('ctype');
                var ctotal = $("input[name='total']").val();
                if($(this).val() == 0){
                    moneyrefresh(ctotal,0);
                    return;
                }

                if(ctype == 1){
                        //体验券
                        moneyrefresh(0,ctotal);
                    }else{
                        var cjianmian = $(this).attr("dataa");
                        var cdikou    = $(this).attr("datab");
                        if(parseInt(ctotal) >= parseInt(cjianmian)){
                            moneyrefresh(ctotal-cdikou,cdikou);
                        }else{
                            moneyrefresh(ctotal,0);
                        }
                    }
            })
        })
    </script>

</body>
</html>